<template>
    <div class="body changePassword">
        <div class="cpbox">
            <div class="cpli">
                <span>旧密码</span>
                <input type="text" placeholder="请输入旧密码" v-model="oldpass">
            </div>
            <div class="cpli">
                <span>新密码</span>
                <input type="password" placeholder="请输入新密码" v-model="newpass">
            </div>
            <div class="cpli">
                <span>确认密码</span>
                <input type="password" placeholder="请输入新密码" v-model="newpass2">
            </div>
        </div>
        <div class="cp_btn" @click="changepasword()">确定</div>
    </div>
</template>

<script>
    import {Toast} from 'mint-ui';
    export default {
        name: "changePassword",
        data() {
            return {
                oldpass:'',
                newpass:'',
                newpass2:''
            }
        },
        methods: {
            changepasword() {
                if(this.oldpass==''||this.newpass==''||this.newpass2==''){
                    return Toast({
                        message: "请输入完整信息",
                        position: 'center',
                        duration: 2000
                    });
                }
                if(this.newpass!=this.newpass2){
                    return Toast({
                        message: "两次密码不一致",
                        position: 'center',
                        duration: 2000
                    });
                }

                this.axios({
                    method: 'get',
                    url: 'apis/partner/updatePassword?newPassword='+this.newpass2+'&oldPassword='+this.oldpass,
                    data: this.qs.stringify({
                        oldPassword:this.oldpass,
                        newPassword:this.newpass2
                    }),
                    withCredentials: true,
                }).then((response) => {
                    console.log(response)
                    if(response.data.code!=0){
                        Toast({
                            message: response.data.message,
                            position: 'center',
                            duration: 2000
                        });
                    }
                    Toast({
                        message: "密码修改成功",
                        position: 'center',
                        duration: 2000
                    });
                    this.$router.push({path: '/perSon', query: {}})
                }).catch((error) => {
                    console.log(error)
                });
            }
        }
    }
</script>

<style scoped lang="less">
    .changePassword {
        background: rgba(244, 244, 244, 1);

        .cpbox {
            background: #fff;
            overflow: hidden;
            margin-top: 0.2rem;

            .cpli {
                margin: 0 0.3rem;
                height: 0.9rem;
                line-height: 0.9rem;
                border-bottom: 1px solid rgba(237, 237, 237, 1);

                span {
                    font-size: 0.3rem;
                    width: 1.3rem;
                    float: left;
                }

                input {
                    height: 0.6rem;
                    line-height: 0.6rem;
                    float: left;
                    border: 0;
                    margin-top: 0.15rem;
                    padding: 0 0.2rem;
                    min-width: 5rem;
                }
            }
        }

        .cp_btn {
            position: fixed;
            left: 0;
            bottom: 0;
            width: 100%;
            height: 1rem;
            background: rgba(35, 106, 246, 1);
            color: #fff;
            font-size: 0.32rem;
            text-align: center;
            line-height: 1rem;
            cursor: pointer;
            letter-spacing: 2px;
        }
    }
</style>
